<template>
  <div id="app">
    <router-view v-transition/>
  </div>
</template>
<script>
import axios from 'axios';

export default {
  mounted() {
    // 测试添加分享
    axios({
      url: 'https://share.eschervr.com/share',
      params: {
        url: window.location.href
      },
      method: 'GET'
    })
    .then((res) => {
      const { data } = res;
      wx.config({
        debug: false,
        appId: data.appId,
        timestamp: data.timestamp,
        nonceStr: data.nonceStr,
        signature: data.signature,
        jsApiList: [
          'updateAppMessageShareData',
          'updateTimelineShareData'
        ]
      });

      const shareData = {
        title: '七彩云南，旅游天堂',
        link: data.url,
        imgUrl: 'http://res.eschervr.com/assets/resource/logo.png',
        desc: '云南建成一批以高山峡谷、现代冰川、高原湖泊、石林、喀斯特洞穴、火山地热、原始森林、花卉、文物古迹、传统园林及少数民族风情等为特色的旅游景区，同时拥有独特的民族节庆、非遗文化、特色美食、特色古村落、半山酒店等文化旅游新名片。'
      };

      wx.ready(() => {
        console.log('配置成功');
        wx.updateAppMessageShareData({
          ...shareData,
          success() {
            console.log('分享好友成功');
          },
          fail() {
            console.log('updateAppMessageShareData 错误');
          }
        });

        wx.updateTimelineShareData({
          ...shareData,
          success() {
            console.log('分享朋友圈成功');
          },
          fail() {
            console.log('updateTimelineShareData 错误');
          }
        });
      });
    })
    // 请求失败
    .catch((e) => {
      throw new Error(e);
    });
  }
};
</script>
